package com.chen.blue.controller.admin.business;

import com.chen.blue.domain.delete.business.ContestApplyActiveDelete;
import com.chen.blue.domain.dto.business.ContestApplyActiveDto;
import com.chen.blue.domain.dto.business.ContestApplyDto;
import com.chen.blue.domain.dto.business.update.ContestApplyActiveDtoEdit;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.R;
import com.chen.blue.service.business.IContestApplyActiveService;
import com.chen.blue.service.business.IContestPersonInfoService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * Created By CLT On 2024/6/8.
 */
@SuppressWarnings("all")
@ApiSort(993)
@Api(tags = "备赛阶段-赛事人员信息上报模块")
@Validated
@RestController
@PreAuthorize("hasRole('ROLE_teacher')")
@RequestMapping("/contest/prepare")
public class ContestPrepareController {

    @Resource
    private IContestApplyActiveService iContestApplyActiveService;

    @Resource
    private IContestPersonInfoService iContestPersonInfoService;

    @ApiOperation(value = "人员信息上报", notes = "人员信息上报")
    @PostMapping("/person/apply/{id}")
    public R applyContestPersonInfo(@PathVariable("id") Long activeId) throws DtoNullException {

        return R.success(iContestApplyActiveService.addContestApplyRelationPerson(activeId));

    }

    @ApiOperation(value = "删除人员信息", notes = "删除人员信息")
    @DeleteMapping("/person/delete/{id}")
    public R deleteContestPersonInfo(@PathVariable("id") Long personId) throws DtoNullException {

        return iContestPersonInfoService.delete(personId) ? R.success() : R.faild();

    }

    @ApiOperation(value = "放弃参赛(流程回到第二阶段初始状态,支持人员信息修改)", notes = "放弃参赛(流程回到第二阶段初始状态,支持人员信息修改)")
    @ApiOperationSupport(ignoreParameters = {"fileBaseOne", "creator", "updater", "optionType"})
    @PostMapping("/abandon")
    public R abandonContest(@Valid @RequestBody ContestApplyActiveDto contestApplyActiveDto) throws DtoNullException {

        return iContestApplyActiveService.forbiddenContestApplyActive(contestApplyActiveDto) ? R.success() : R.faild();

    }

}
